//package com.magina.mq.rabbit.exchange;
//
//import org.springframework.amqp.AmqpException;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import java.util.UUID;
//
///**
// * 文件名称：Sender_02</br>
// * 初始作者： Magina.Hu</br>
// * 创建日期： 2019/5/10</br>
// * 功能说明： 模拟rabbitMq通过exchange发送mq <br/>
// * =================================================<br/>
// * 修改记录：<br/>
// * 修改作者 日期 修改内容<br/>
// * ================================================<br/>
// * Copyright (c) 2019-2020 .All rights reserved.<br/>
// */
//@Component
//public class RabExchangeWithComfirmSend implements RabbitTemplate.ConfirmCallback {
//
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    @Value("${rab.cass.config.exchange}")
//    private String directExchange;
//
//    @Value("${rab.mq.config.exchange}")
//    private String topicExchange;
//
//    @Value("${rab.cass.config.quene.info.routing.key}")
//    private String infoKey;
//
//    @Value("${rab.cass.config.quene.error.routing.key}")
//    private String errorKey;
//
//    @Autowired
//    public RabExchangeWithComfirmSend(RabbitTemplate rabbitTemplate) {
//        this.rabbitTemplate = rabbitTemplate;
//        rabbitTemplate.setConfirmCallback(this);
//    }
//
//
//    /**
//     * 方法描述:  模拟点对点发送 direct类型的Exchange路由规则也很简单，它会把消息路由到那些binding key与routing key完全匹配的Queue中。 </br>
//     * 初始作者: Magina.Hu<br/>
//     * 创建日期: 2019/5/10 <br/>
//     * 开始版本: 1.0.0<br/>
//     * =================================================<br/>
//     * 修改记录：<br/>
//     * 修改作者 日期 修改内容<br/>
//     * ================================================<br/>
//     * @param  入参对象
//     * @return  返回数据
//     * @throws Exception 异常
//     */
//    public void sendWithExchange(Integer type,Integer i ){
//        String msg = "rabbitMq send direct exchange queue msg: type :" ;
//        if(1 == type)
//        this.convertAndSendWithCorrelationData(this.directExchange,this.infoKey,String.format("%s %s.count: %s",msg,infoKey,i));
//        if(2 == type)
//        this.convertAndSendWithCorrelationData(this.directExchange,this.errorKey,String.format("%s %s.count: %s",msg,errorKey,i));
//    }
//
//    private static final String PRODUCT_TOPIC_QEUE_NAME_01 = "product.log.info";
//    private static final String PRODUCT_TOPIC_QEUE_NAME_02 = "product.log.debug";
//    private static final String PRODUCT_TOPIC_QEUE_NAME_03 = "product.log.error";
//    private static final String PRODUCT_TOPIC_QEUE_NAME_04 = "product.log.warn";
//
//    //模拟来自产品的四种日志类型
//    public void sendProductLogWithExchange(Integer i ) {
//        String msg = "rabbitMq send topic exchange queue msg." ;
//        this.convertAndSendWithCorrelationData(this.topicExchange, PRODUCT_TOPIC_QEUE_NAME_01, String.format("%s queueName: %s .count :%s",msg,PRODUCT_TOPIC_QEUE_NAME_01,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, PRODUCT_TOPIC_QEUE_NAME_02, String.format("%s queueName: %s .count :%s",msg,PRODUCT_TOPIC_QEUE_NAME_02,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, PRODUCT_TOPIC_QEUE_NAME_03, String.format("%s queueName: %s .count :%s",msg,PRODUCT_TOPIC_QEUE_NAME_03,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, PRODUCT_TOPIC_QEUE_NAME_04, String.format("%s queueName: %s .count :%s",msg,PRODUCT_TOPIC_QEUE_NAME_04,i));
//    }
//
//    private static final String ORDER_TOPIC_QEUE_NAME_01 = "order.log.info";
//    private static final String ORDER_TOPIC_QEUE_NAME_02 = "order.log.debug";
//    private static final String ORDER_TOPIC_QEUE_NAME_03 = "order.log.error";
//    private static final String ORDER_TOPIC_QEUE_NAME_04 = "order.log.warn";
//
//    //模拟来自订单的四种日志类型
//    public void sendOrderLogWithExchange(Integer i ) {
//        String msg = "rabbitMq send topic exchange queue msg." ;
//        this.convertAndSendWithCorrelationData(this.topicExchange, ORDER_TOPIC_QEUE_NAME_01, String.format("%s queueName: %s .count :%s",msg,ORDER_TOPIC_QEUE_NAME_01,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, ORDER_TOPIC_QEUE_NAME_02, String.format("%s queueName: %s .count :%s",msg,ORDER_TOPIC_QEUE_NAME_02,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, ORDER_TOPIC_QEUE_NAME_03, String.format("%s queueName: %s .count :%s",msg,ORDER_TOPIC_QEUE_NAME_03,i));
//        this.convertAndSendWithCorrelationData(this.topicExchange, ORDER_TOPIC_QEUE_NAME_04, String.format("%s queueName: %s .count :%s",msg,ORDER_TOPIC_QEUE_NAME_04,i));
//    }
//
//    void convertAndSendWithCorrelationData (String var1, String var2, String var3) throws AmqpException{
//        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
//        System.out.println("callbackSender UUID: " + correlationData.getId());
//        this.rabbitTemplate.convertAndSend(var1,var2,var3, correlationData);
//    }
//
//    @Override
//    public void confirm(CorrelationData correlationData, boolean b, String s) {
//        if(b){
//            System.out.println("confirm: " + correlationData.getId() + ",s=" + s + ",b:" + b);
//        }else{
//            System.out.println("消费失败");
//        }
//
//    }
//}
